package com.elinkway.infinitemovies.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.elinkway.infinitemovies.bean.MainHeaderBean;
import com.le123.ysdq.R;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

/**
 * Created by liuxiaojiang on 2016/11/25
 */
public class AllTabAdapter extends MyBaseAdapter {

    private ArrayList<MainHeaderBean> headerList;

    private class GridItemHolder {
        ImageView imageView;
        TextView title;
    }

    public AllTabAdapter(Context context, ArrayList<MainHeaderBean> headerList) {
        super(context);
        this.headerList = headerList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final MainHeaderBean bean = headerList.get(position);
        GridItemHolder holder;
        if (convertView == null) {
            holder = new GridItemHolder();
            convertView = View.inflate(mContext, R.layout.all_home_tab_item, null);
            holder.imageView = (ImageView) convertView.findViewById(R.id.home_header_item_iv);
            holder.title = (TextView) convertView.findViewById(R.id.home_header_item_tv);
            convertView.setTag(holder);
        } else {
            holder = (GridItemHolder) convertView.getTag();
        }
        if(bean != null){
            if(!TextUtils.isEmpty(bean.getIcon())){
                ImageLoader.getInstance().displayImage(bean.getIcon(), holder.imageView);
            }
            holder.title.setText(bean.getName());
        }
        return convertView;
    }

    @Override
    public int getCount() {
        return headerList.size();
    }

}
